<%@ page import="connect.InfoDao" %>
<%@ page import="java.util.List" %>
<%@ page import="model.Info" %>
<%@ page import="java.util.ArrayList" %><%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>User</title>
</head>
<body>
<jsp:include page="top.jsp"/>
<%
    //先获取状态为2的交易单号列表
    request.setCharacterEncoding("UTF-8");
    // 获取上一个页面传过来的值
    String username = request.getParameter("name");
    System.out.println("用户名:" + username);
    // 传入的空字符串处理,null不能使用equals
    if (username != null && username.equals("")) {
        username = null;
    }
    InfoDao infoDao = new InfoDao();
    List<Integer> tradelist = infoDao.getTradeByNameAndStatus(username,2);
    if (tradelist==null){
        tradelist = new ArrayList<>();
    }
%>
<section class="service_section layout_padding1">
    <div class="container">
        <div class="heading_container">
            <h2>
                用户
            </h2>
            <h3>若您对订单信息有异议，请联系收货地管理人员为您查询区块详细信息</h3>
        </div>
    </div>
</section>

<div class="contact-form" style="text-align: center;margin-top: 0px;">
<form action="receiver.jsp" name="nameForm1" >
    <input type="text" name="name" id="name" placeholder="输入您的用户名来查询订单" style="border: none;
  outline: none;
  background-color: transparent;
  width: 30%;
  margin: 15px 0;
  padding: 10px 20px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 30px;">
    <button type="submit" class="btn_on-hover" onclick="return checkName1()" style="border: none;
  outline: none;
  display: inline-block;
  padding: 10px 25px;
  background-color: #582fd7;
  color: #ffffff;
  border-radius: 5px;
  text-transform: uppercase;
  margin-top: 15px;">
        查询
    </button>
</form>
</div>

<script type="text/javascript">
    function checkName1() {
        var name = nameForm1.name.value;
        if (name == "" || name == null) {
            alert("请输入用户名");//弹出提示
            nameForm1.name.focus();//把鼠标焦点移到name里
            return false;
        }
        return true;
    }
</script>

<div class="contact-form" style="text-align: center;">
    <form action="receiverDo2.jsp" name="nameForm" >
        <input type="text" name="name" id="name" placeholder="输入订单号来查询物流公司a交易详情" style="border: none;
  outline: none;
  background-color: transparent;
  width: 30%;
  margin: 15px 0;
  padding: 10px 20px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 30px;">
        <button type="submit" class="btn_on-hover" onclick="return checkName2()" style="border: none;
  outline: none;
  display: inline-block;
  padding: 10px 25px;
  background-color: #582fd7;
  color: #ffffff;
  border-radius: 5px;
  text-transform: uppercase;
  margin-top: 15px;">
            查询
        </button>
    </form>
</div>

<script type="text/javascript">
    function checkName2() {
        var name = nameForm.name.value;
        if (name == "" || name == null) {
            alert("请输入订单号");//弹出提示
            nameForm.name.focus();//把鼠标焦点移到name里
            return false;
        }
        return true;
    }
</script>

<div class="contact-form" style="text-align: center;">
    <form action="receiverDo3.jsp" name="nameForm" >
        <input type="text" name="name" id="name" placeholder="输入订单号来查询物流公司b交易详情" style="border: none;
  outline: none;
  background-color: transparent;
  width: 30%;
  margin: 15px 0;
  padding: 10px 20px;
  border: 1px solid rgba(0, 0, 0, 0.4);
  border-radius: 30px;">
        <button type="submit" class="btn_on-hover" onclick="return checkName3()" style="border: none;
  outline: none;
  display: inline-block;
  padding: 10px 25px;
  background-color: #582fd7;
  color: #ffffff;
  border-radius: 5px;
  text-transform: uppercase;
  margin-top: 15px;">
            查询
        </button>
    </form>
</div>

<script type="text/javascript">
    function checkName3() {
        var name = nameForm.name.value;
        if (name == "" || name == null) {
            alert("请输入订单号");//弹出提示
            nameForm.name.focus();//把鼠标焦点移到name里
            return false;
        }
        return true;
    }
</script>

<div style="display:flex;flex-direction: column;align-items:center;justify-content: center;">
    <button type="submit" style="padding: 10px 25px;width:13%;
  background-color: #582fd7;
  color: #ffffff;
  border-radius: 5px;
  margin-bottom: 15px;
  text-transform: uppercase;" onclick="window.location.href='purchase.jsp'">
        购买物流公司a商品
    </button>

    <button type="submit" style="padding: 10px 25px;width:13%;
  background-color: #582fd7;
  color: #ffffff;
  border-radius: 5px;
  text-transform: uppercase;" onclick="window.location.href='purchase1.jsp'">
        购买物流公司b商品
    </button>
</div>

<div style="display: flex;flex-direction: row">
    <!-- didntArriveDestination section -->
    <div class="service_section layout_padding1" style="width:33%;align-items: center">
        <div class="container" style="align-items: center;justify-content: center">
            <div class="heading_container">
                <h3>
                    未送至收货点商品
                </h3>
            </div>
            <div class="service_container" style=";width: 100%">
                <%
                    List<Integer> tradelist0=infoDao.getTradeByNameAndStatus(username,1);
                    tradelist = infoDao.getTradeByNameAndStatus(username,0);
                    if (tradelist==null){
                        tradelist = new ArrayList<>();
                    }
                    if(tradelist0!=null){
                        tradelist.addAll(tradelist0);
                    }
                    for (int i = 0; i < tradelist.size(); i++) {
                        int trade=tradelist.get(i);
                %>

                <div class="detail-box" style="border: 2px gray solid;width: 300px;margin-bottom: 15px">
                    <table align="center" cellspacing="0">
                        <tr  style="font-size: 20px;height:60px;text-align: center">
                            <td style="width:  150px">订单号</td>
                            <td style="width: 150px">用户名</td>
                            <td style="width: 150px">价格</td>
                            <td style="width: 150px">物流</td>
                        </tr>
                        <%
                            List<Info> infoList1 = infoDao.getInfoByTradeAndStatus(trade,0);
                            List<Info> infoList = infoDao.getInfoByTradeAndStatus(trade,1);
                            if(infoList1!=null&&infoList!=null){
                                infoList.addAll(infoList1);
                            } else if (infoList1!=null&&infoList==null) {
                                infoList=infoList1;
                            }

                            //如果用户没有购买任何商品，为infoList设置一个默认值避免报错
                            if(infoList==null||infoList.size()==0){
                                Info temp=new Info();
                                temp.setName("未查询到结果");
                                temp.setId(0);
                                temp.setOrg(1);
                                temp.setPrice(0);
                                infoList.add(temp);
                            }
                            int org=1;
                            if(infoList.get(0).getOrg()=="蓝天物流"){
                                org=1;
                            }
                            else{
                                org=2;
                            }
                            for (int j=0;j<infoList.size();j++){
                                Info in=infoList.get(j);
                        %>
                        <tr style="height:40px;text-align: center">
                            <td><%=in.getId()%>
                            </td>
                            <td><%=in.getName()%>
                            </td>
                            <td><%=in.getPrice()%>
                            </td>
                            <td><%=in.getOrg()%>
                            </td>
                        </tr>
                        <%
                            }
                        %>
                        <tr style="height:30px;text-align: center"></tr>
                    </table>
                </div>

                <%
                    }
                %>

            </div>
        </div>
    </div>
    <!-- didntArriveDestination section -->

    <!-- arrivedDestination section -->
    <div class="service_section layout_padding1" style="width:33%;align-items: center">
        <div class="container" style="align-items: center;justify-content: center">
            <div class="heading_container">
                <h3>
                    已送至收货点商品
                </h3>
            </div>
            <div class="service_container" style=";width: 100%">
                <%
                    tradelist = infoDao.getTradeByNameAndStatus(username,2);
                    if (tradelist==null){
                        tradelist = new ArrayList<>();
                    }
                    for (int i = 0; i < tradelist.size(); i++) {
                        int trade=tradelist.get(i);
                %>

                <div class="detail-box" style="border: 2px gray solid;width: 300px;margin-bottom: 15px">
                    <table align="center" cellspacing="0">
                        <tr  style="font-size: 20px;height:60px;text-align: center">
                            <td style="width:  150px">订单号</td>
                            <td style="width: 150px">用户名</td>
                            <td style="width: 150px">价格</td>
                            <td style="width: 150px">物流</td>
                        </tr>
                        <%
                            List<Info> infoList = infoDao.getInfoByTradeAndStatus(trade,2);
                            //如果用户没有购买任何商品，为infoList设置一个默认值避免报错
                            if(infoList==null||infoList.size()==0){
                                Info temp=new Info();
                                temp.setName("未查询到结果");
                                temp.setId(0);
                                temp.setOrg(1);
                                temp.setPrice(0);
                                infoList.add(temp);
                            }
                            int org=1;
                            if(infoList.get(0).getOrg()=="蓝天物流"){
                                org=1;
                            }
                            else{
                                org=2;
                            }
                            for (int j=0;j<infoList.size();j++){
                                Info in=infoList.get(j);
                        %>
                        <tr style="height:40px;text-align: center">
                            <td><%=in.getId()%>
                            </td>
                            <td><%=in.getName()%>
                            </td>
                            <td><%=in.getPrice()%>
                            </td>
                            <td><%=in.getOrg()%>
                            </td>
                        </tr>
                        <%
                            }
                        %>
                        <tr style="height:30px;text-align: center"></tr>
                    </table>
                    <div class="btn-box">
                        <a href="receiverDo.jsp?status=2&org=<%=org%>&trade=<%=trade%>">
                            确认
                        </a>
                    </div>
                </div>

                <%
                    }
                %>

            </div>
        </div>
    </div>
    <!-- arrivedDestination section -->

    <!-- confirmed section -->
    <div class="service_section layout_padding1" style="width:33%;align-items: center">
        <div class="container" style="align-items: center;justify-content: center">
            <div class="heading_container">
                <h3>
                    已收到商品
                </h3>
            </div>
            <div class="service_container" style="width: 100%">
                <%
                    tradelist = infoDao.getTradeByNameAndStatus(username,3);
                    if (tradelist==null){
                        tradelist = new ArrayList<>();
                    }
                    for (int i = 0; i < tradelist.size(); i++) {
                        int trade = tradelist.get(i);
                %>

                    <div class="detail-box" style="border: 2px gray solid;width: 300px;margin-bottom: 15px">
                        <table align="center" cellspacing="0">
                            <tr  style="font-size: 20px;height:60px;text-align: center">
                                <td style="width:  150px">订单号</td>
                                <td style="width: 150px">用户名</td>
                                <td style="width: 150px">价格</td>
                                <td style="width: 150px">物流</td>
                            </tr>
                            <%
                                List<Info> infoList = infoDao.getInfoByTradeAndStatus(trade,3);
                                //如果用户没有购买任何商品，为infoList设置一个默认值避免报错
                                if(infoList==null||infoList.size()==0){
                                    Info temp=new Info();
                                    temp.setName("未查询到结果");
                                    temp.setId(0);
                                    temp.setOrg(1);
                                    temp.setPrice(0);
                                    infoList.add(temp);
                                }

                                for (int j=0;j<infoList.size();j++){
                                    Info in=infoList.get(j);
                            %>
                            <tr style="height:40px;text-align: center">
                                <td><%=in.getId()%>
                                </td>
                                <td><%=in.getName()%>
                                </td>
                                <td><%=in.getPrice()%>
                                </td>
                                <td><%=in.getOrg()%>
                                </td>
                            </tr>
                            <%
                                }
                            %>
                            <tr style="height:30px;text-align: center"></tr>
                        </table>
                    </div>
                <%
                    }
                %>

            </div>
        </div>
    </div>


</div>
<jsp:include page="footer.jsp"/>

</body>
</html>
